//
//  BaseTableViewController.swift
//  WeiBoSwift
//
//  Created by rong on 15/6/24.
//  Copyright © 2015年 rong. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController , VisitorLoginViewDelegate {
    
    //var userLogin = true
    var userLogin = (sharedUserAccount != nil)
    
    var visitorView: VisitorLoginView?
    
    override func loadView() {
        
        print("用户是否登录？\(userLogin)")
        print("hhhh \(sharedUserAccount)");
        
        userLogin ? super.loadView() : setupVisitorView()
        
    }

  
    //创建访客视图
    private func setupVisitorView()
    {
        visitorView = VisitorLoginView()
        visitorView?.delegate = self
        view = visitorView
        
        //添加导航栏视图
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorRegisterButtonClicked")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginButtonClicked")
    }
    
    //注册
    func visitorRegisterButtonClicked()
    {
        print("navigationItem  的 注册")
    }
    
    
    //登录
    func visitorLoginButtonClicked()
    {
        //print("navigationItem  的 登录")
        
        let oauth = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauth)
        
        presentViewController(nav, animated: true, completion: nil)
    }

}
